package wid;

import static org.junit.Assert.assertTrue;
import robocode.control.testing.RobotTestBed;
import robocode.BattleResults;
import robocode.control.events.BattleCompletedEvent;

/**
 * This test simply verifies that Pacifist does not lose every round to SittingDuck.
 * 
 * @author Philip Johnson
 * @author David Wilkie
 */
public class TestPacifistVersusSittingDuck extends RobotTestBed {

  /**
   * Specifies that SittingDuck and Pacifist are to be matched up in this test case.
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,wid.Pacifist";
  }
  
  /**
   * This test runs for 10 rounds.
   * @return The number of rounds. 
   */
  @Override
  public int getNumRounds() {
    return 10;
  }
  
  /**
   * The actual test, which asserts that DaCruzer has won or tied 90% of rounds 
   * against SittingDuck.  On rare occasions (<5% of the time) it loses a round.
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    // Return the results in order of getRobotNames.
    BattleResults[] battleResults = event.getIndexedResults();
    // Sanity check that results[1] is DaCruzer (not strictly necessary, but illustrative).
    BattleResults pacifistResults = battleResults[1];
    // Check to make sure Pacifist .
    assertTrue("Check Pacifist won/tied 95% of rounds", 
        pacifistResults.getFirsts() >= getNumRounds() - 1);
  }
}
